package com.gewu.ordlelist.fragment;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityOptionsCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.gewu.ordlelist.R;
import com.gewu.ordlelist.activity.moreActivity;
import com.gewu.ordlelist.adapter.oneAdapter;
import com.gewu.ordlelist.base.BaseFragment;
import com.gewu.ordlelist.utils.oneItemClick;

public class oneFragment extends BaseFragment implements oneItemClick {

    RecyclerView rec;

    @Override
    public View FindView(LayoutInflater inflater) {
        return inflater.inflate(R.layout.one_fragment, null, false);
    }

    @Override
    public void initView(View view) {
        Toolbar toolbar = view.findViewById(R.id.toolbar);
        rec = view.findViewById(R.id.rec);
        toolbar.setTitle(setToolbarText());
    }

    @Override
    public String setToolbarText() {
        return "NewOneDay";
    }

    @Override
    public void setAdapter() {
        oneAdapter oneAdapter = new oneAdapter(this);
        GridLayoutManager linearLayoutManager = new GridLayoutManager(getContext(), 2);
        linearLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                if (position == 0) {
                    return 2;
                } else {
                    return 1;
                }
            }
        });
        rec.setLayoutManager(linearLayoutManager);
        rec.setAdapter(oneAdapter);
        oneAdapter.notifyDataSetChanged();
    }


    @Override
    public void showOnClick2(int index,String name,View view) {
        Intent intent = new Intent(getContext(), moreActivity.class);
        intent.putExtra("index",index);
        intent.putExtra("name",name);
        ActivityOptionsCompat optionsCompat =
                ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), view, "image");
        startActivity(intent,optionsCompat.toBundle());
    }

    @Override
    public void showOnClick(int index) {

    }

}
